package com.apps.ftapp.act;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.activity.BaseActivity;
import com.apps.ftapp.model.ShouYiModel;
import com.apps.ftapp.util.ActivitySkipUtil;
import com.apps.ftapp.util.Async;
import com.apps.ftapp.util.Constant;
import com.apps.ftapp.util.L;
import com.apps.ftapp.util.Tools;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import cz.msebera.android.httpclient.Header;

/**
 * 我的收益
 */
public class ShouYiActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.jine)
    TextView jine;
    @BindView(R.id.daijiesuan)
    TextView daijiesuan;
    @BindView(R.id.yijiesuan)
    TextView yijiesuan;
    @BindView(R.id.tops)
    RelativeLayout tops;
    @BindView(R.id.xianjin)
    TextView xianjin;
    @BindView(R.id.tixian)
    TextView tixian;
    @BindView(R.id.tixian_container)
    RelativeLayout tixianContainer;
    @BindView(R.id.shourumingxi)
    TextView shourumingxi;
    @BindView(R.id.tixianzhanghu)
    TextView tixianzhanghu;
    @BindView(R.id.shangweishezhi)
    TextView shangweishezhi;

    private ShouYiModel result = new ShouYiModel();
    private Gson gson = new Gson();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shou_yi);
        ButterKnife.bind(this);

        setTitle("我的收益");

        tixian.setOnClickListener(this);
        shourumingxi.setOnClickListener(this);
        tixianzhanghu.setOnClickListener(this);

        initView();

        loadData();

    }

    private void loadData() {

        RequestParams params = new RequestParams();
        params.put("userId", Constant.uid);
        params.put("token", Constant.token);
        Async.post("course/share/account", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                if (statusCode == 200) {
                    L.i("main", new String(responseBody) + "......");
                    result = gson.fromJson(new String(responseBody), ShouYiModel.class);
                    if (Tools.isIntNull(result.getSuccess()) == 1) {

                        jine.setText(result.getData().getZyongjin() + "");
                        daijiesuan.setText(result.getData().getDyongjin() + "");
                        yijiesuan.setText(result.getData().getYyongjin() + "");
                        xianjin.setText(result.getData().getKyongjin() + "");

                        if ("0".equals(result.getData().getShareaccountset())) {

                            shangweishezhi.setVisibility(View.VISIBLE);
                        } else {
                            shangweishezhi.setVisibility(View.GONE);
                        }

                    }

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }
        });

    }

    private void initView() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.tixian:
                HashMap<String, Object> map = new HashMap<>();
                map.put("money", result.getData().getKyongjin());
                ActivitySkipUtil.skipAnotherActivity(ShouYiActivity.this, TiXianActivity.class, map);
                break;
            case R.id.shourumingxi:
                ActivitySkipUtil.skipAnotherActivity(ShouYiActivity.this, TxJlActivity.class, false);
                break;

            case R.id.tixianzhanghu:
                ActivitySkipUtil.skipAnotherActivity(ShouYiActivity.this, BankActivity.class, false);
                break;
        }
    }
}
